<template>
	<view class="container">
		<view class="head">
			<u-tabs bgColor="#fff" inactive-color="#666666" barWidth="80" barHeight="4" :height="80"
				active-color="#1684FC" :list="t_list" :is-scroll="false" font-size='28' :bold="false" :current="t_index"
				@change="changetheme"></u-tabs>
		</view>
		<view style="width: 100%; height: 100%; padding-top: 80rpx;" v-if="t_index != 1">
			<view class="addBox flex-ac">
				<view class="inputBox flex-ac">
					<image src="../../../static/img/ss.png" mode=""></image>
					<input v-model="form.carNo" type="text" placeholder="请输入车牌号" />
				</view>
				<view class="btn-search" @click="search">查询</view>
			</view>
			<view class="carList">
				<view class="item" v-for="(item,index) in list" :key="index" @click.stop="selCar(index)">
					<image class="icon-car" src="../../../static/img/car.png" mode="aspectFill"></image>
					<view class="cell flex-ac">
						<view style="font-size: 30rpx;">{{item.carNo || ''}}/{{getDictName(item.carType)}} </view>
						<view class="label" v-if='item.type == 1'>自有车辆</view>
						<view class="label2" v-if='item.type == 2'>外调车辆</view>
					</view>
					<view class="cell flex-ac" style="margin-top: 20rpx;">
						<view>{{item.driverName || ''}}-{{item.driverPhone || ''}}</view>
					</view>
					<view class="cell flex-ac">
						<view>预警时间：{{item.warningTime || '-'}}</view>
					</view>
					<view class="cell flex-ac">
						<view>空闲时间：{{item.idleDuration || '-'}}小时</view>
					</view>
					<view class="shanchuBox">
						<!-- <image v-if="item.sel" src="../../../static/img/choice_gou.png" mode="aspectFill"></image>
						<image v-else src="../../../static/img/choice_no.png" mode="aspectFill"></image> -->
					</view>
				</view>
			</view>
		</view>
		<view class="carTotal" v-if="t_index == 1">
			<view class="carBox">
				<view>在途车辆：{{car.carNum2 || ''}}</view>
				<view>空闲车辆：{{car.carNum1 || ''}}</view>
				<view>空闲预警：{{car.carNumIdleWarning || ''}}</view>
				<view>休假车辆：{{car.carNum3 || ''}}</view>
				<view>维修车辆：{{car.carNum4 || ''}}</view>
			</view>
		</view>
		<view class="foot flexmid-col" @click="$Jump.Open('./warning')" v-if="t_index != 1">
			<image src="/static/img/yujing.png" mode=""></image>
			<view>预警</view>
			<view>设置</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				list: '',
				form:{
					carNo: '',
					current: 1,
					size: 10
				},
				dict: [],
				isNext: true,
				t_list: [{
						name: '车辆列表'
					},
					{
						name: '车辆总览'
					}
				],
				t_index: 1,
				car: {}
			}
		},
		onLoad(opt) {
			if(opt) console.log('opt:', opt)
			this.id = opt.id
			// this.getCarList()
			this.getDict()
			this.getCarData()
		},
		onReachBottom() {
			this.form.current++
			this.getCarList()
		},
		methods: {
			changetheme(index) {
				this.t_index = index;
				this.queryForm.current = 1
				if (this.t_index === 0) {
					this.restStatus = 'wait_audit'
				} else if (this.t_index === 1) {
					this.restStatus = 'passed'
				} else if (this.t_index === 2) {
					this.restStatus = 'reject'
				}
				this.getList()
			},
			submit(){
				let arr = this.list.filter(item=>item.sel)
				if(arr.length == 0){
					this.$Toast.message('请选择车辆')
					return
				}else{
					var isAllDriver = true
					arr.map(el=>{
						if(!el.driverId){
							isAllDriver = false
							console.log('请完善车辆司机信息')
						}
					})
					if(!isAllDriver){
						this.$Toast.message('请完善车辆司机信息')
						return
					}
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2]
					prevPage.$vm.getData(arr)
					this.$Jump.Back(1)
				}
			},
			search(){
				this.form.current = 1
				this.getCarList()
			},
			selCar(index){
				this.list[index].sel = !this.list[index].sel
			},
			setDriver(index){
				this.$Jump.Open('../selDriver/selDriver?index=' + index)
			},
			getCarData(){
				this.$Net.get('/car/count').then(res=>{
					console.log('车辆总览:', res)
					this.car = res.data
				})
			},
			getCarList(){
				if(!this.isNext) return
				this.isNext = false
				this.$Net.get('/car/pageIdle', this.form).then(res=>{
					console.log('车辆列表：', res)
					if(res.data.length > 0){
						res.data.map(el=>{
							el.sel = false
						})
					}
					if(this.form.current == 1){
						this.list = res.data
					}else{
						this.list = this.list.concat(res.data)
					}
					this.isNext = true
				})
			},
			getDictName(id){
				return this.dict.find(item=>item.code == id).name || ''
			},
			// 获取字典数据
			getDict(){
				this.$Net.get('/sysDict/code/car_type').then(res=>{
					console.log('字典数据:', res)
					this.dict = res.data
					this.getCarList()
				})
			},
		
		}
	}
</script>

<style lang="scss">
	page{ background-color: #f7f7f7; }
</style>

<style lang="scss" scoped>
	// @import './style.scss';
	.carTotal{
		width: 100%;
		padding: 24rpx;
		padding-top: 100rpx;
		.carBox{
			width: 100%;
			min-height: 300rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 30rpx;
			view{
				height: 100rpx;
				width: 100%;
				border-bottom: 1rpx solid #f7f7f7;
				line-height: 100rpx;
				font-size: 30rpx;
			}
		}
	}
	.head{
		background-color: #ffffff;
		width: 100%;
		height: 82rpx;
		position: fixed;
		border-bottom: 1rpx solid #f7f7f7;
		padding-bottom: 2rpx;
		top: 0;
		left: 0;
		z-index: 10;
	}
	.carList{
		width: 100%;
		// padding-top: 100rpx;
		padding-bottom: 60rpx;
		.item{
			position: relative;
			padding: 28rpx;
			padding-left: 90rpx;
			width: 100%;
			border-bottom: 1rpx solid #f7f7f7;
			font-size: 24rpx;
			.icon-car{
				width: 50rpx;
				height: 50rpx;
				position: absolute;
				top: 30rpx;
				left: 25rpx;
			}
			.shanchuBox{
				padding: 40rpx;
				position: absolute;
				right: 10rpx;
				top: 50%;
				transform: translateY(-50%);
				image{
					width: 40rpx;
					height: 40rpx;
				}
			}
			.cell{
				margin-bottom: 8rpx;
				.setDr{
					margin-left: 20rpx;
					color: #1684FC;
					font-size: 24rpx;
					text-decoration: underline;
				}
			}
			.label{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #f2f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
			.label2{
				padding: 6rpx 12rpx;
				border-radius: 4rpx;
				color: #333;
				font-size: 24rpx;
				background-color: #a1f981;
				margin-left: 10rpx;
				border: 1px solid rgba(199, 199, 199, 1);
			}
		}
	}
	.addBox{
		width: 100%;
		height: 100rpx;
		padding-left: 30rpx;
		font-size: 28rpx;
		border-bottom: 1rpx solid #f7f7f7;
		background-color: #ffffff;
		// position: fixed;
		// top: 0;
		// left: 0;
		// z-index: 10;
		.inputBox{
			flex: 1;
			height: 70rpx;
			border-radius: 40rpx;
			background-color: #f7f7f7;
			padding: 0 20rpx;
			input{
				flex: 1;
				color: #333;
			}
		}
		.btn-search{
			height: 100rpx;
			line-height: 100rpx;
			padding: 0 30rpx;
			color: #1F82FE;
		}
		image{
			width: 40rpx;
			height: 40rpx;
			margin-right: 10rpx;
		}
	}
	.foot {
		position: fixed;
		bottom: 150rpx;
		padding: 0;
		right: 20rpx;
		width: 110rpx;
		height: 110rpx;
		background: #1684FC;
		border-radius: 50%;
		color: #ffffff;
		font-size: 20rpx;
		image{
			width: 35rpx;
			height: 35rpx;
		}
	}
</style>
